#include <stdio.h>
#include <memory.h>

#include "tools.h"
#include "sm3.h"

static bool Test_01() {
    const char* m = "abc";
    const uint8_t valueExpect[] = {
        0x66, 0xc7, 0xf0, 0xf4, 0x62, 0xee, 0xed, 0xd9,
        0xd1, 0xf2, 0xd4, 0x6b, 0xdc, 0x10, 0xe4, 0xe2,
        0x41, 0x67, 0xc4, 0x87, 0x5c, 0xf2, 0xf7, 0xa2,
        0x29, 0x7d, 0xa0, 0x2b, 0x8f, 0x4b, 0xa8, 0xe0 };
    uint8_t value[SM3_HASH_LENGTH];

    SM3_Hash(m, 3, value);

    return memcmp(value, valueExpect, SM3_HASH_LENGTH) == 0;
}

static bool Test_02() {
    const char* m = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd";
    const uint8_t valueExpect[] = {
		0xde, 0xbe, 0x9f, 0xf9, 0x22, 0x75, 0xb8, 0xa1, 
		0x38, 0x60, 0x48, 0x89, 0xc1, 0x8e, 0x5a, 0x4d, 
		0x6f, 0xdb, 0x70, 0xe5, 0x38, 0x7e, 0x57, 0x65, 
		0x29, 0x3d, 0xcb, 0xa3, 0x9c, 0x0c, 0x57, 0x32
	};

    uint8_t value[SM3_HASH_LENGTH];

    SM3_Hash(m, strlen(m), value);

    return memcmp(value, valueExpect, SM3_HASH_LENGTH) == 0;
}

bool SM_Test_SM3() {
	bool r  = true;

	r = SM_TEST(Test_01()) && r;
	r = SM_TEST(Test_02()) && r;

	return r;
	
}


